package com.wuliu.driver.controller;

import com.aliyun.oss.OSSClient;
import com.wuliu.driver.pojo.DriverRealname;
import com.wuliu.driver.service.DriverRealnameService;
import com.wuliu.driver.util.Code;
import com.wuliu.driver.util.Oss;
import com.wuliu.driver.util.Result;
import com.wuliu.driver.util.UploadImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;



@RestController
@RequestMapping("/realname")
public class DriverRealnameController {
    @Autowired
    private UploadImg uploadImg;
    @Autowired
    private DriverRealnameService driverRealnameService;
    //上传身份证照片
    @PostMapping("/idcard")
    public Result idCard(MultipartFile file) throws IOException {
        String upload = uploadImg.upload(file);
        DriverRealname driverRealname = uploadImg.idCard(file);
        if (driverRealname.getName()!=null){
            driverRealname.setImagez(upload);
        }else {
            driverRealname.setImagef(upload);
        }
        return new Result(Code.GET_OK,driverRealname,"上传成功");
    }
    //上传从业资格证
    @PostMapping("/qualification")
    public Result qualification(MultipartFile file) throws IOException {
        String upload = uploadImg.upload(file);
        return new Result(Code.GET_OK,upload,"上传成功");
    }

    //提交审核
    @PostMapping("/ins")
    public Result ins (@RequestBody DriverRealname driverRealname){

        return driverRealnameService.ins(driverRealname);
    }

    //查询所有审核是否通过
    @GetMapping("/select/{did}")
    public Result select(@PathVariable Integer did){
        return driverRealnameService.select(did);
    }
}
